package com.heima.wemedia.controller.v1;

import com.heima.model.article.dtos.ArticleCommentDetailDto;
import com.heima.model.article.dtos.ArticleCommentDto;
import com.heima.model.comment.dtos.ApCommentDto;
import com.heima.model.comment.dtos.CommentPageDto;
import com.heima.model.comment.pojos.ApComment;
import com.heima.model.common.dtos.CommentLikeDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.wemedia.service.WmCommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/v1/comment/manage/")
public class WmCommentController {

    @Autowired
    private WmCommentService wmCommentService;

    /**
     * 评论管理列表
     * @param dto
     * @return
     */
    @PostMapping("find_news_comments")
    public PageResponseResult findNewsComments(@RequestBody ArticleCommentDto dto){
        return wmCommentService.findNewsComments(dto);
    }

    /**
     * 查看文章评论详情
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ArticleCommentDetailDto dto){
        log.info("dto:{}",dto);
        return wmCommentService.list(dto);
    }

    /**
     * 点赞
     * @param dto
     * @return
     */
    @PostMapping("/like")
    public ResponseResult like(@RequestBody CommentLikeDto dto){
        return wmCommentService.like(dto);
    }

    /*
     * 删除评论
     * */
    @DeleteMapping("/del_comment/{commentId}")
    public ResponseResult delComment(@PathVariable("commentId") String commentId){
        return wmCommentService.delComment(commentId);
    }


    /*
     * 删除评论回复
     * */
    @DeleteMapping("/del_comment_repay/{commentRepayId}")
    public ResponseResult delCommentRepay(@PathVariable("commentRepayId") String commentRepayId){
        return wmCommentService.delCommentRepay(commentRepayId);
    }

    /**
     * 文章评论开启或关闭状态
     * @param dto
     * @return
     */
    @PostMapping("/update_comment_status")
    public ResponseResult updateCommentStatus(@RequestBody ApCommentDto dto){
        log.info("评论状态:{}",dto);
        return wmCommentService.updateCommentStatus(dto);
    }

    /**
     * 作者回复评论
     * @param dto
     * @return
     */
    @PostMapping("/comment_repay")
    public ResponseResult commentRepay(@RequestBody CommentPageDto dto){
        log.info("回复评论:{}",dto);
        return wmCommentService.commentRepay(dto);
    }

}
